package com.xbk.platform.junit;

import static org.junit.Assert.*;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;

import com.xbk.platform.BusinessObject;
import com.xbk.platform.DaoUtil;
import com.xbk.platform.DataMap;
import com.xbk.platform.sql.ConnectionMananger;

public class BusinessObjectTest {
	
	private DaoUtil du = null;
	private BusinessObject bo = null; 
	
	@Before
	public void setUp() throws Exception {
		this.du = ConnectionMananger.getDaoUtil();
	}

	@After
	public void tearDown() throws Exception {
		this.du.close();
	}

	@Test
	public void test() throws Exception {
		bo = new BusinessObject("USERID", "USER_INFO", du);
		bo.loadData("WHERE USERID = 'XXXX'");
		assertEquals("XXXX", bo.getAttribute("USERID"));
	}
	
	@Test
	public void add() throws Exception {
		bo = new BusinessObject("USERID", "USER_INFO", du);
		DataMap data = bo.getEmptyData();
		data.put("USERID", "XXXX");
		data.put("PASSWORD", "12345");
		data.put("STATUS", "03");
		data.put("PASSWD", "12345");
		bo.save();
	}
	
	@Test
	public void delete() throws Exception{
		bo = new BusinessObject("USERID", "USER_INFO", du);
		bo.loadData("WHERE USERID = 'XXXX'");
		bo.deleteDB();
	}
	
	@Test
	public void upload() throws Exception{
		bo = new BusinessObject("USERID", "USER_INFO", du);
		bo.loadData("WHERE USERID = 'XXXX'");
		bo.setAttribute("PASSWD", "c121231").setAttribute("status", "c12321").setAttribute("username", "c231231");
		bo.setNeedBack(true);
		bo.updateDB();
		System.out.println(bo.getAttribute("PASSWD"));
	}
	
	@Test
	public void backUp() throws Exception{
		bo = new BusinessObject("USERID", "USER_INFO", du);
		bo.loadData("WHERE USERID = 'XXXX'");
		assertEquals("XXXX", bo.getAttribute("USERID"));
	}
	
	
}
